﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ConvergensDominoConnector;

namespace CDCOSDH
{
    public partial class ActiveIncomingByCaseOfficer : Form
    {
        private string sdhName;
        private string viewName;
        
        public List<string> selectedRow = new List<string>(10);

        public ActiveIncomingByCaseOfficer(string sdhName, string viewName)
        {
            InitializeComponent();

            this.sdhName = sdhName;
            this.viewName = viewName;
            this.Text = "Sagsbehandlernes indgående i restance i " + this.sdhName + " SDH";

            this.dTActiveIncomingByCaseOfficer.Select();
        }

        private void ActiveIncomingByCaseOfficer_Load(object sender, EventArgs e)
        {
            DataTable dataTable = DominoConnector.Default.GetActiveIncomingByCaseOfficer(this.viewName, this.sdhName);
            this.dTActiveIncomingByCaseOfficer.DataSource = dataTable;
            this.dTActiveIncomingByCaseOfficer.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
            this.dTActiveIncomingByCaseOfficer.Columns["Svar-løbenummer"].HeaderText = "Svarløbenummer";
            this.dTActiveIncomingByCaseOfficer.Columns["UNID"].Visible = false;
        }

        private void btnCnl_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }


        private void dTActiveIncomingByCaseOfficer_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            List<string> selectedRow = new List<string>(10);
            foreach (DataGridViewRow row in this.dTActiveIncomingByCaseOfficer.SelectedRows)
            {
                selectedRow.Add(row.Cells[1].Value.ToString());
                selectedRow.Add(row.Cells[0].Value.ToString());
                selectedRow.Add(row.Cells[3].Value.ToString());
            }

            this.selectedRow.AddRange(selectedRow);
            selectedRow = null;
            this.DialogResult = DialogResult.OK;
        }

        private void dTActiveIncomingByCaseOfficer_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.dTActiveIncomingByCaseOfficer.SelectedRows.Count == 0)
            {
                return;
            }

            if (e.KeyCode == Keys.Enter)
            {
                List<string> selectedRow = new List<string>(10);
                foreach (DataGridViewRow row in this.dTActiveIncomingByCaseOfficer.SelectedRows)
                {
                    selectedRow.Add(row.Cells[1].Value.ToString());
                    selectedRow.Add(row.Cells[0].Value.ToString());
                    selectedRow.Add(row.Cells[3].Value.ToString());
                }

                this.selectedRow.AddRange(selectedRow);
                selectedRow = null;
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
